<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function strLen(str){
      let result = 1; // 存储长度
      let norepeatStr = ''; // 存储无重复字符串
      let len = str.length;
      for(let i = 0; i< len; i++){
        // 获取对用的字符
        let specStr = str.charAt(i);
        // 获取index
        let index = norepeatStr.indexOf(specStr);
        if(index === -1){
          norepeatStr += specStr;
          result < norepeatStr.length ? norepeatStr : result;
        } else {
          norepeatStr = norepeatStr.substr(index+1) + specStr;
        }
      }
      return result;
    }

    console.log(strLen('ae'));
  </script>
</body>
</html>